package com.fjnu.dao.impl;

import java.util.List;

import javax.persistence.criteria.CriteriaBuilder.In;

import org.springframework.stereotype.Repository;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;

import com.fjnu.dao.IUserDao;
import com.fjnu.dao.common.BaseDaoImpl;
import com.fjnu.dao.common.DaoException;
import com.fjnu.entities.User;
@Repository("userDao")
public class UserDao extends BaseDaoImpl<User> implements IUserDao {

	
	public User loginFindUnique(String idnumber) {
		//String idnumber=user.getIdnumber();
		//System.out.println(idnumber);
		String hql = "from User where idnumber = ?";
		List<User> listUser = findByHQL(hql,idnumber);
		//System.out.println("ddd"+listUser.get(0));
		if(listUser.size()==0){
			return null;
		}
		return listUser.get(0);
	}
	public List<User> findUser(Integer pageNo,Integer pageSize) {
		String hql="from User";
		List<User> list = queryPage(hql,pageNo,pageSize);
		if(list.size()==0){
			throw new DaoException("用户列表为空");
		}
		return list;
	}
	public void UpdateUser(Integer id, String name, String password) {
		String[] names={"name","password"};
		partUpdate(id, names,name,password);
	}
	public void delUser(Integer id) {
		delete(id);
		
	}
	public User findUserUnique(int id) {
	
		return findById(id);
	}
	public void updateUser(User user){
		update(user);
	}

	@Override
	public void saveUser(User user) {
		save(user);
		
	}

}
